<%@ page import="service.PhotographerService" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath = request.getContextPath();
    String path = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+basePath+"/";
    request.setAttribute("path",path);
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>微信支付</title>
</head>
<script type="text/javascript" src="${path}/js/jweixin-1.0.0.js"></script>
<script type="text/javascript" src="${path}/js/jquery-2.1.1.min.js"></script>
<script>
    function onBridgeReady(){
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', {
             "appId": "wx079bba8222507669",     //公众号名称，由商户传入
            "timeStamp":"${timeStamp}",         //时间戳，自1970年以来的秒数
            "nonceStr":"${nonce_str}", //随机串
            "package":"prepay_id=${prepay_id}",
            "signType": "MD5",         //微信签名方式：
            "paySign": "${sign}" //微信签名
    },
        function(res){
                //alert(JSON.stringify(res));
                //alert(res.err_msg);
            if(res.err_msg == "get_brand_wcpay_request：ok" ) {
                document.getElementById("form1").submit();
                <%System.out.print("ok");%>
            }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
            if(res.err_msg == "get_brand_wcpay_request：cancel" ) {
                <%System.out.print("cancel");%>
            }
            if(res.err_msg == "get_brand_wcpay_request：fail" ) {
                <%System.out.print("fail");%>
            }
            location.href="http://www.kaaction.com/Admin/kaToShoots";
        }
    );
    }
    if (typeof WeixinJSBridge == "undefined"){
        if( document.addEventListener ){
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        }else if (document.attachEvent){
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    }else{
        onBridgeReady();
    }
</script>
<body>
<%--</br></br></br></br>
<div align="center">
    <button style="width:210px; height:30px; background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer;  color:white;  font-size:16px;" type="button" onclick="onBridgeReady()" >微信支付</button>
</div>--%>
<form id="form1" name="form1" method="post" action="${path}/kdIndex">
    <input id="type" name="type" value="1" style="display: none">
    <input id="orderCode" name="orderCode" value="${orderCode}" style="display: none">
</form>
</body>
</html>
